package fragments;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.wangjin.menu.AssignmentDetailActivity;
import com.example.wangjin.menu.R;

/**
 * Created by wangjin on 15/5/30.
 */
public class AssignmentFragment extends ListFragment {

    private String[] assignmentName = {"HCI草图设计","HCI程序设计","HCI原型设计","HCI期末答辩"};
    private listAdapter l;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        l = new listAdapter(assignmentName);
        setListAdapter(l);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        Intent i = new Intent(getActivity(), AssignmentDetailActivity.class);
        startActivity(i);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.project_list,container,false);
        return v;
    }

    class listAdapter extends ArrayAdapter<String>{

        private String[] assignmentName;

        public listAdapter(String[] assignmentName){
            super(getActivity(),0,assignmentName);
            this.assignmentName = assignmentName;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null) {
                convertView = getActivity().getLayoutInflater().
                        inflate(R.layout.assignmentitem, null);
                TextView t = (TextView)convertView.findViewById(R.id.assignmentName);
                t.setText(assignmentName[position]);
                return convertView;
            }else {
                return convertView;
            }

        }
    }
}
